#ifdef MAC_OS_X
	#include "GDAL/ogrsf_frmts.h"
	#include <GDAL/ogr_spatialref.h>
#else
	#include "ogrsf_frmts.h"
	#include <ogr_spatialref.h>
#endif


OGRDataSource *geojsonFromShp() {
    OGRDataSource *srcDS = NULL;
    srcDS = OGRSFDriverRegistrar::Open( "xgl1.shp", FALSE );
    if( srcDS == NULL ) {
        exit(1);
    }
    
    OGRLayer *layer = srcDS->GetLayer(0);
    printf("layer info: %s\n", layer->GetInfo("ALL"));
    
    OGRSFDriver *jsonDriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName("GeoJSON");

    OGRDataSource *dstDS;
    dstDS = jsonDriver->CopyDataSource(srcDS, "test0.json", NULL);
/*    
    dstDS  = jsonDriver->CreateDataSource("test.json", NULL);
    if( dstDS == NULL ) {
        printf( "Creation of output file failed.\n" );
        exit( 1 );
    }
    printf("ok\n");
    OGRFieldDefn oField( "Name", OFTString );
    oField.SetWidth(32);
    OGRLayer *poLayer = dstDS->CreateLayer("test", NULL, wkbUnknown, NULL);
    if( poLayer->CreateField( &oField ) != OGRERR_NONE ) {
        printf( "Creating Name field failed.\n" );
        exit( 1 );
    }
//*/  
    return dstDS;
}

int main() {
    OGRRegisterAll();
    
    OGRDataSource *jsonDS = geojsonFromShp();
    OGRDataSource::DestroyDataSource(jsonDS);
}
